widget-factory: Test busy state
authorMatthias Clasen <mclasen@redhat.com>
Thu, 30 Jul 2015 14:32:44 +0000 (10:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 30 Jul 2015 14:36:34 +0000 (10:36 -0400)
Makes it easy to test insensitive state of widgets.i
Also exposes brokenness in the shell busy indicator...

demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index f17894d47d208a84f3190f565ef2be8ba27d2aaf..c86fd11c8a29130800280926a31a0dacc05eeddb 100644 (file)
@@ -41,6 +41,37 @@ change_theme_state (GSimpleAction *action,
   g_simple_action_set_state (action, state);
 }
 
+static gboolean
+get_idle (gpointer data)
+{
+  GtkWidget *window = data;
+  GtkApplication *app = gtk_window_get_application (GTK_WINDOW (window));
+
+  gtk_widget_set_sensitive (window, TRUE);
+  gdk_window_set_cursor (gtk_widget_get_window (window), NULL);
+  g_application_unmark_busy (G_APPLICATION (app));
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+get_busy (GSimpleAction *action,
+          GVariant      *parameter,
+          gpointer       user_data)
+{
+  GtkWidget *window = user_data;
+  GdkCursor *cursor;
+  GtkApplication *app = gtk_window_get_application (GTK_WINDOW (window));
+
+  g_application_mark_busy (G_APPLICATION (app));
+  cursor = gdk_cursor_new_from_name (gtk_widget_get_display (window), "wait");
+  gdk_window_set_cursor (gtk_widget_get_window (window), cursor);
+  g_object_unref (cursor);
+  g_timeout_add (5000, get_idle, window);
+
+  gtk_widget_set_sensitive (window, FALSE);
+}
+
 static void
 activate_search (GSimpleAction *action,
                  GVariant      *parameter,
@@ -1256,7 +1287,8 @@ activate (GApplication *app)
   static GActionEntry win_entries[] = {
     { "dark", NULL, NULL, "false", change_theme_state },
     { "search", activate_search, NULL, NULL, NULL },
-    { "delete", activate_delete, NULL, NULL, NULL }
+    { "delete", activate_delete, NULL, NULL, NULL },
+    { "busy", get_busy, NULL, NULL, NULL }
   };
   struct {
     const gchar *action_and_target;
index fc6459dda70c20b3a9af65cb17faa2d4e6ea20c7..fb79661b6322b628f5bd410a1d0569b1220d4d6c 100644 (file)
@@ -3,6 +3,10 @@
   <!-- interface-requires gtk+ 3.0 -->
   <menu id="gear_menu">
     <section>
+      <item>
+        <attribute name="label" translatable="yes">Get Busy</attribute>
+        <attribute name="action">win.busy</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">Dark Theme</attribute>
         <attribute name="action">win.dark</attribute>